﻿#include"Tree.h"


// 前序遍历 
void PerOrder(BTNode* root)
{
	if (root == NULL)
		return;
	cout << root->data << ' ';
	PerOrder(root->left);
	PerOrder(root->right);
}
// 中序遍历
void InOrder(BTNode* root)
{
	if (root == NULL)
		return;
	InOrder(root->left);
	cout << root->data << ' ';
	InOrder(root->right);
}
//  后序遍历
void PostOrder(BTNode* root)
{
	if (root == NULL)
		return;
	PostOrder(root->left);
	PostOrder(root->right);
	cout << root->data << ' ';
}
// 二叉树结点个数
int BinaryTreeSize(BTNode* root)
{
	if (root == NULL)
	{
		return 0;
	}
	return 1 + BinaryTreeSize(root->left) + BinaryTreeSize(root->right);
}
//  二叉树叶子结点个数
int BinaryTreeLeafSize(BTNode* root)
{
	if (root == NULL)
		return 0;
	if (root->left == NULL && root->right == NULL)
	{
		return 1;
	}
	return BinaryTreeLeafSize(root->left) + BinaryTreeLeafSize(root->right);
}
// ⼆叉树第k层结点个数
int BinaryTreeLevelKSize(BTNode* root, int k)
{
	if (root == NULL)
		return 0;
	if (k == 1)
		return 1;
	return BinaryTreeLevelKSize(root->left, k - 1) + BinaryTreeLevelKSize(root->right, k - 1);
}
// 二叉树的深度/高度  
int BinaryTreeDepth(BTNode* root)
{
	if (root == NULL)
		return 0;
	return 1 + max(BinaryTreeDepth(root->left), BinaryTreeDepth(root->right));
}
// ⼆叉树查找值为x的结点
BTNode* BinaryTreeFind(BTNode* root, BTDataType x)
{
	if (root == NULL)
		return NULL;
	if (root->data == x)
		return root;
	BTNode* leftfind = BinaryTreeFind(root->left,x);
	if (leftfind)
		return leftfind;
	BTNode* rightfind = BinaryTreeFind(root->right,x);
	if (rightfind)
		return rightfind;
	return NULL;
}
// 二叉树的销毁  
void BinaryTreeDestory(BTNode** root)
{


}